package com.yaopaikeji.controller;

import com.yaopaikeji.constants.Constants;
import com.yaopaikeji.interceptor.Auth;
import com.yaopaikeji.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class HomeController {

    @Autowired
    private UserService userService;

    @RequestMapping("/")
    public String index() {
        return "index";
    }

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login() {
        return "login";
    }

    @RequestMapping(value = "/main-page", method = RequestMethod.GET)
    public String toAdmin() {

        //已经登陆
        if(userService.isLogined()){
            return "information-list";
        }

        //未登录或未知权限
        return "login";
    }

    @Auth(Constants.ROLE_ROOT_NAME)
    @RequestMapping(value = "/user/management",method = RequestMethod.GET)
    public String toUserManagement(){

        return "employee-list";
    }

    @Auth(Constants.ROLE_ADMIN_NAME)
    @RequestMapping(value = "/test")
    public String test() {
        return "test";
    }

    @Auth(Constants.ROLE_ROOT_NAME)
    @RequestMapping(value = "/user/add",method = RequestMethod.GET)
    public String toAdd() {
        return "employee-add";
    }

    @Auth(Constants.ROLE_ROOT_NAME)
    @RequestMapping(value = "/user/emailgroup",method = RequestMethod.GET)
    public String toEmail() {
        return "email-group";
    }

    @Auth(Constants.ROLE_ROOT_NAME)
    @RequestMapping(value = "/user/addEmail",method = RequestMethod.GET)
    public String toaddEmail() {
        return "new-emailgroup";
    }

    @Auth(Constants.ROLE_ROOT_NAME)
    @RequestMapping(value = "/user/success",method = RequestMethod.GET)
    public String toSuccse() {
        return "up-success";
    }

    @Auth(Constants.ROLE_ROOT_NAME)
    @RequestMapping(value = "/user/fail",method = RequestMethod.GET)
    public String tofail() {
        return "up-fail";
    }

    @Auth(Constants.ROLE_ROOT_NAME)
    @RequestMapping(value = "/user/addpopu",method = RequestMethod.GET)
    public String toAddPop() {
        return "Popup-emailadd";
    }

    @Auth(Constants.ROLE_ROOT_NAME)
    @RequestMapping(value = "/user/emailDetails",method = RequestMethod.GET)
    public String toemailDetail() {
        return "emailgroup-details";
    }
}
